﻿<UserControl x:Class="ConsoleHoster.View.Controls.DriveExplorerView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:cv="clr-namespace:ConsoleHoster.View.Converters"
             xmlns:uc="clr-namespace:ConsoleHoster.Common.Controls;assembly=ConsoleHoster.Common"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300" DataContextChanged="UserControl_DataContextChanged_1">
    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="cvBooleanToVisibilityConverter"/>
        <cv:ExplorerItemToImageSourceConverter x:Key="cvExplorerItemToImageSourceConverter" />
        <cv:ItemStateToVisibilityConverter x:Key="cvItemStateToVisibilityConverter" />
    </UserControl.Resources>

    <TreeView ItemsSource="{Binding Drives}" Background="White" VerticalAlignment="Stretch">
        <TreeView.ItemContainerStyle>
            <Style TargetType="{x:Type TreeViewItem}">
                <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                <Setter Property="FontWeight" Value="Normal" />
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="FontWeight" Value="Bold" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </TreeView.ItemContainerStyle>

        <TreeView.ItemTemplate>
            <HierarchicalDataTemplate ItemsSource="{Binding Children}">
                <StackPanel Orientation="Horizontal" Margin="0, 2, 0, 0" HorizontalAlignment="Left">
                    <StackPanel.ContextMenu>
                        <ContextMenu Width="250">
                            <MenuItem Header="{Binding Path=ExplorerItem.Name}" IsEnabled="False" />
                            <MenuItem Click="OnContextMenu_OpenExplorer" Visibility="{Binding IsNotFile, Converter={StaticResource cvBooleanToVisibilityConverter}}">
                                <MenuItem.Header>
                                    <Grid HorizontalAlignment="Stretch">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Text="Explorer" HorizontalAlignment="Left" />
                                        <TextBlock Width="30" Grid.Column="1" />
                                        <TextBlock Text="Ctrl+[Right Click]" HorizontalAlignment="Right" Grid.Column="2" />
                                    </Grid>
                                </MenuItem.Header>
                            </MenuItem>
                            <MenuItem Click="OnContextMenu_UsePath">
                                <MenuItem.Header>
                                    <Grid HorizontalAlignment="Stretch">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Text="Use Path" HorizontalAlignment="Left" />
                                        <TextBlock Width="30" Grid.Column="1" />
                                        <TextBlock Text="Ctrl+[Click]" HorizontalAlignment="Right" Grid.Column="2" />
                                    </Grid>
                                </MenuItem.Header>
                            </MenuItem>
                            <MenuItem Click="OnContextMenu_UseName">
                                <MenuItem.Header>
                                    <Grid HorizontalAlignment="Stretch">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Text="Use Name" HorizontalAlignment="Left" />
                                        <TextBlock Width="30" Grid.Column="1" />
                                        <TextBlock Text="Alt+[Click]" HorizontalAlignment="Right" Grid.Column="2" />
                                    </Grid>
                                </MenuItem.Header>
                            </MenuItem>
                            <MenuItem Click="OnContextMenu_RedirectTo" Visibility="{Binding IsNotFile, Converter={StaticResource cvBooleanToVisibilityConverter}}">
                                <MenuItem.Header>
                                    <Grid HorizontalAlignment="Stretch">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Text="Redirect To" HorizontalAlignment="Left" />
                                        <TextBlock Width="30" Grid.Column="1" />
                                        <TextBlock Text="Shift+[Click]" HorizontalAlignment="Right" Grid.Column="2" />
                                    </Grid>
                                </MenuItem.Header>
                            </MenuItem>
                            <MenuItem Click="OnContextMenu_Favorite">
                                <MenuItem.Header>
                                    <Grid HorizontalAlignment="Stretch">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Text="Add as Favorite..." HorizontalAlignment="Left" />
                                        <TextBlock Width="30" Grid.Column="1" />
                                        <TextBlock Text="Alt+[Right Click]" HorizontalAlignment="Right" Grid.Column="2" />
                                    </Grid>
                                </MenuItem.Header>
                            </MenuItem>
                            <MenuItem Click="OnContextMenu_Run" Visibility="{Binding IsFile, Converter={StaticResource cvBooleanToVisibilityConverter}}">
                                <MenuItem.Header>
                                    <Grid HorizontalAlignment="Stretch">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Text="Run" HorizontalAlignment="Left" />
                                        <TextBlock Width="30" Grid.Column="1" />
                                        <TextBlock Text="[Double Click]" HorizontalAlignment="Right" Grid.Column="2" />
                                    </Grid>
                                </MenuItem.Header>
                            </MenuItem>
                        </ContextMenu>
                    </StackPanel.ContextMenu>
                    <uc:WaitIndicator Width="10" Height="10" Visibility="{Binding Path=ItemState, Converter={StaticResource cvItemStateToVisibilityConverter}}" />
                    <Image Name="img" MaxWidth="15" MaxHeight="15" Source="{Binding Path=ExplorerItem,  Converter={StaticResource cvExplorerItemToImageSourceConverter}}" MouseLeftButtonDown="OnExplorerItem_MouseLeftButtonDown" MouseLeftButtonUp="OnExplorerItem_MouseLeftButtonUp" MouseRightButtonUp="OnExplorerItem_MouseRightButtonUp" HorizontalAlignment="Left" />
                    <TextBlock Text="{Binding Path=ExplorerItem.Alias}" Margin="5,0" MouseLeftButtonDown="OnExplorerItem_MouseLeftButtonDown" MouseLeftButtonUp="OnExplorerItem_MouseLeftButtonUp" MouseRightButtonUp="OnExplorerItem_MouseRightButtonUp" Foreground="{Binding Path=ItemStateColor}" />
                </StackPanel>
            </HierarchicalDataTemplate>
        </TreeView.ItemTemplate>
    </TreeView>
</UserControl>
